<?php
/**
 * User: yuesir
 * Date: 2016/4/26
 * Time: 23:24
 */

define('BASE_DIR', __DIR__);
include BASE_DIR.'/Lib/Loader.php';

spl_autoload_register('\\Lib\\Loader::autoload');

$obj = new \Lib\Object();
//echo $obj->title;

//$db = new Lib\Database\MySQLi();
//$db->connect('localhost', 'root', '', 'test');



class Page {
    function index()
    {
        $user_info = Lib\Factory::getUser(1);
        $user_info->name = 'yuesir_xiaohei';

        $this->test();
    }


    function test()
    {
        $user_info = Lib\Factory::getUser(1);
        $user_info->mobile = '18682480989';
    }
}

class Event extends \Lib\EventGenerator
{
    function trigger()
    {
        echo "event triggerd";
        $this->notify();
    }
}

class Observer1 implements \Lib\Observer
{
    function update($event_info = null) {
        echo "<br/>逻辑一<br/>";
    }
}

$event = new Event();
$event->addObserver(new Observer1());
$event->trigger();

$page = new Page();
$page->index();

//使用ArrayAcess实现配置文件的加载
//$config = new Lib\Config(BASE_DIR . '/Config');
//var_dump($config['controller']);


$allUser = new \Lib\AllUsers();
foreach($allUser as $user) {
    var_dump($user->name);
}
/**
 * 装饰器模式的使用
 */
//$canvas = new \Lib\Canvas();
//$canvas->init();
//$canvas->rect(2, 3, 2, 3);
//$canvas->addDecorator(new \Lib\ColorDecorator('green'));
//$canvas->addDecorator(new \Lib\SizeDecorator('20px'));
//$canvas->draw();


//栈
//$stack = new SplStack();
//$stack->push('data1\n');
//$stack->push('data2\n');
//
//echo $stack->pop();
//echo $stack->pop();


//队列
//$queue = new SplQueue();
//$queue->enqueue('data1\n');
//$queue->enqueue('data2\n');
//
//echo $queue->dequeue();
//echo $queue->dequeue();

//堆
